<template>
  <el-radio-group
    :value="value"
    @input="handleInput"
    class="decoration-group"
    :class="`has-${hasImage ? 'image' : 'text'}`"
  >
    <el-radio
      :label="option.value"
      v-for="(option, index) in options"
      :key="index"
    >
      <div v-if="option.image" class="decoration-group-radio">
        <div class="decoration-group-style">
          <img :src="option.image" />
        </div>
        <p class="decoration-group-radio-text">
          {{ option.title || option.label }}
        </p>
      </div>
      <span v-else>{{ option.label }}</span>
      <el-tooltip
        placement="right"
        effect="dark2"
        popper-class="survey_tooltip_test"
        v-if="option.showTips"
      >
        <div slot="content">
          <ul>
            <li
              v-for="(item, index) in filterTipsText(option.tipsTexts)"
              v-bind:key="index"
            >
              {{ item }}
            </li>
          </ul>
        </div>
        <i class="el-icon-question"></i>
      </el-tooltip>
    </el-radio>
  </el-radio-group>
</template>

<script>
// import CardRadio from '../card-radio';
export default {
  // components: { CardRadio },
  props: {
    options: {
      type: Array,
      default() {
        return [];
      },
    },
    value: {
      type: String | Number | Boolean,
    },
    optionType: {
      type: String,
      default: "style",
    },
  },

  computed: {
    hasImage() {
      return !!this.options[0].image;
    },
  },

  methods: {
    handleInput(val) {
      this.$emit("input", val);
      this.$emit("change", val);
    },
    filterTipsText(texts) {
      if (!texts) {
        return [];
      } else if (typeof texts === "string") {
        return [texts];
      } else if (Array.isArray(texts)) {
        return texts;
      } else {
        return [];
      }
    },
  },
};
</script>

<style lang="less">
.decoration-group {
  &-radio {
    display: inline-block;
    margin-left: 4px;
    &-text {
      padding: 4px 0 0 0;
    }
  }
  .el-radio {
    font-size: 12px;
    margin-right: 12px;
  }
  .el-radio__label {
    display: inline-block;
    font-size: 12px;
    padding-left: 6px;
    padding-top: 4px;
  }
  &-style {
    width: 50px;
    height: 50px;
    background: #fff;
    border: 1px dashed #f2f2f2;
    display: inline-block;
    img {
      width: 100%;
      height: 100%;
    }
  }
  &.has-text .el-radio + .el-radio {
    margin-left: 20px;
  }
  &.item-block .el-radio + .el-radio {
    display: block !important;
    margin: 8px 0 0 0 !important;
  }
  &.has-image .el-radio {
    margin-bottom: 10px;
    margin-left: 0;
    .el-radio__input {
      margin-top: -67px;
    }
    &:nth-child(3n + 1) {
      margin-left: 0 !important;
    }
  }

  .el-radio.is-checked {
    .decoration-group-radio-text {
      color: #29b6b0;
    }
  }
}
</style>
